package com.nuoniu.sibanyun.mapper.erp.in;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.entity.dto.InInventoryInfoDto;
import com.nuoniu.sibanyun.entity.dto.InInventoryInfoSearchDto;
import com.nuoniu.sibanyun.entity.dto.statistics.InventoryStorageOnHandDto;
import com.nuoniu.sibanyun.entity.dto.statistics.StorageOnHandDto;
import com.nuoniu.sibanyun.entity.erp.in.InInventoryInfo;
import com.nuoniu.sibanyun.entity.inOut.VInOutRecordDetail;
import com.nuoniu.sibanyun.entity.vo.InInventoryCheckSearchVo;
import com.nuoniu.sibanyun.entity.vo.statistics.InventoryStorageOnHandVo;
import com.nuoniu.sibanyun.entity.vo.statistics.StorageOnHandVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 物料信息 Mapper 接口
 * </p>
 *
 * @author 小啊刚
 * @since 2020-12-28
 */
public interface InInventoryInfoMapper extends BaseMapper<InInventoryInfo> {

    @Select("select sum(inventory_quantity) from scw_current_stock where inventory_id=#{inventoryId} and warehouse_id in (${warehouseIds}) and company_id=#{companyId}")
    Double getInventoryCountByWarehouse(Integer inventoryId, String warehouseIds, Integer companyId);

    @Select("select sum(inventory_quantity) from scw_current_stock where inventory_id=#{inventoryId} and company_id=#{companyId}")
    Double getInventoryCount(Integer inventoryId, Integer companyId);

    /**
     * 获取物料的现存量（所有仓库）
     * @param companyId
     * @param accountId
     * @param inventoryId
     * @return
     */
    BigDecimal getExistQuantity(Integer companyId,Integer accountId,Integer inventoryId);

    /**
     * 批量获取物料的现存量
     * @param companyId
     * @param accountId
     * @param inventoryIds
     * @return
     */
    List<HashMap<String,Object>> listExistQuantity(Integer companyId,Integer accountId,List<Integer> inventoryIds);

    /**
     * 批量获取物料的现存量（指定仓库）
     * @param companyId
     * @param inventoryIds
     * @param warehouseId
     * @return
     */
     List<HashMap<String,Object>> listExistQuantityByWarehouseId(Integer companyId,Integer accountId,List<Integer> inventoryIds, Integer warehouseId);



    /**
     * 现存量 统计（按 物料统计）
     * @return
     */
    Page<StorageOnHandVo> statisticStorageOnHandDetailVo (Page page,Integer companyId,Integer accountId,@Param("dto") StorageOnHandDto storageOnHandDto);

    /**
     * 现存量 统计 （按 物料、仓库、货位 统计）
     * @param inventoryIds
     * @return
     */
    List<StorageOnHandVo> statisticStorageOnHandVo(String inventoryIds,@Param("dto") StorageOnHandDto storageOnHandDto);


    /**
     * 盘点业务 查询现存量
     * @param page
     * @param inInventoryInfoSearchDto
     * @return
     */
    Page<InInventoryCheckSearchVo> pageInInventoryCheckSearchVo(Page page, Integer companyId,@Param("dto")InInventoryInfoSearchDto inInventoryInfoSearchDto);


    /**
     * 盘点业务 查询现存量(单个物料)
     */
    InInventoryCheckSearchVo inInventoryCheckSearchVo(Integer companyId,Long warehouseId,String inventoryCode);


    /**
     * 库存 现存量 统计
     * @param companyId
     * @param accountId
     * @param inventoryStorageOnHandDto
     * @return
     */
    List<InventoryStorageOnHandVo> statisticInventoryStorageOnHandVo(Integer companyId, Integer accountId,@Param("dto")InventoryStorageOnHandDto inventoryStorageOnHandDto);
}
